import Vue from 'vue'
import App from './App.vue'
import router from './router'
import 'lib-flexible/flexible'
import axios from 'axios'
import VueAxios from 'vue-axios'
import waterfall from 'vue-waterfall2'
import { 
  Search,
  Tab,
  Tabs,
  Swipe,
  SwipeItem,
  Toast,
  NoticeBar,
  NavBar,
  Icon,
  Sidebar,
  Button,
  SidebarItem,
  Field,
  Form,
  Popup
 } from 'vant';
 
Vue.use(Search);
Vue.use(Tab);
Vue.use(Tabs);
Vue.use(Swipe);
Vue.use(SwipeItem);
Vue.use(Toast);
Vue.use(NoticeBar);
Vue.use(NavBar);
Vue.use(Icon);
Vue.use(Sidebar);
Vue.use(SidebarItem);
Vue.use(Button);
Vue.use(Form);
Vue.use(Field);
Vue.use(Popup);

Vue.use(VueAxios, axios);

Vue.use(waterfall);

Vue.config.productionTip = false

// 添加请求拦截器
axios.interceptors.request.use(function (config) {
  // 在发送请求之前做些什么
  //启动加载提示
  Toast.loading({
    message: '加载中...',
    //禁止穿透点击
    forbidClick: true,
    loadingType: 'spinner',
    //不会自动关闭提示
    duration: 0
  })
  return config;
}, function (error) {
  // 对请求错误做些什么
  Toast.clear();
  return Promise.reject(error);
});

// 添加响应拦截器
axios.interceptors.response.use(function (response) {
  // 对响应数据做点什么
  Toast.clear();
  return response;
}, function (error) {
  // 对响应错误做点什么
  Toast.clear();
  return Promise.reject(error);
});


new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
